package com.hex.ds.hdtp.core.inf.data.transfer.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hex.ds.hdtp.core.inf.common.page.Page;
import com.hex.ds.hdtp.core.inf.common.page.converter.IPageAndMyBatisPlusPageConverter;
import com.hex.ds.hdtp.core.inf.data.transfer.mapper.IDataTransferListMapper;
import com.hex.ds.hdtp.core.inf.data.transfer.po.DataTransferListPo;
import com.hex.ds.hdtp.core.inf.data.transfer.repository.IDataTransferListRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Package: com.hex.ds.hdtp.core.inf.data.transfer.repository.impl
 * @ClassName DataTransferListRepository
 * @Description: 数据迁移清单-数据服务接口实现
 * @Author: wz.li
 * @Date 2023/8/17 17:23
 * @Version v2.0.2
 **/
@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class DataTransferListRepository implements IDataTransferListRepository {

    private final IDataTransferListMapper dataTransferListMapper;

    private final IPageAndMyBatisPlusPageConverter pageConverter;

    /*
     * @Method: queryListByPage <br>
     * @Param: [dataTransferListPo, toPage] <br>
     * @Return: com.hex.ds.hdtp.core.inf.common.page.Page<com.hex.ds.hdtp.core.inf.data.transfer.po.DataTransferListPo> <br>
     * @Description：分页查询<br>
     * @Author： wz.li<br>
     * @Date： 2023/8/17 19:43 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public Page<DataTransferListPo> queryListByPage(DataTransferListPo dataTransferListPo, Page toPage) {
        final IPage tmpPageReslt = dataTransferListMapper.queryListByPage(
                pageConverter.toMyBatisPlusPage(toPage)
                , dataTransferListPo
        );
        final List list = tmpPageReslt.getRecords();
        final Page pageResult = pageConverter.toPage(tmpPageReslt);
        return pageResult.setData(list);
    }

    /*
     * @Method: queryListByTaskId <br>
     * @Param: [dataTransferTaskPkId] <br>
     * @Return: java.util.List<com.hex.ds.hdtp.core.inf.data.transfer.po.DataTransferListPo> <br>
     * @Description：根据数据迁移任务主键查询对应的迁移清单<br>
     * @Author： wz.li<br>
     * @Date： 2023/8/22 17:37 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public List<DataTransferListPo> queryListByTaskId(String dataTransferTaskPkId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("data_transfer_task_pk_id", dataTransferTaskPkId);
        return dataTransferListMapper.selectList(queryWrapper);
    }

    /*
     * @Method: queryById <br>
     * @Param: [pkId] <br>
     * @Return: com.hex.ds.hdtp.core.inf.data.transfer.po.DataTransferListPo <br>
     * @Description：根据主键查询 <br>
     * @Author： wz.li<br>
     * @Date： 2023/8/17 19:42 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public DataTransferListPo queryById(String pkId) {
        return dataTransferListMapper.selectById(pkId);
    }

    /*
     * @Method: add <br>
     * @Param: [dataTransferListPo] <br>
     * @Return: java.lang.Integer <br>
     * @Description：新增<br>
     * @Author： wz.li<br>
     * @Date： 2023/8/17 19:42 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public Integer add(DataTransferListPo dataTransferListPo) {
        return dataTransferListMapper.insert(dataTransferListPo);
    }

    /*
     * @Method: modifyById <br>
     * @Param: [dataTransferListPo] <br>
     * @Return: java.lang.Integer <br>
     * @Description：根据主键更新<br>
     * @Author： wz.li<br>
     * @Date： 2023/8/17 19:42 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public Integer modifyById(DataTransferListPo dataTransferListPo) {
        return dataTransferListMapper.updateById(dataTransferListPo);
    }

    /*
     * @Method: removeById <br>
     * @Param: [pkId] <br>
     * @Return: java.lang.Integer <br>
     * @Description：根据主键删除<br>
     * @Author： wz.li<br>
     * @Date： 2023/8/17 19:42 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public Integer removeById(String pkId) {
        return dataTransferListMapper.deleteById(pkId);
    }
}
